package com.hk.service.sys.impl;

import com.hk.commons.HqlFilter;
import com.hk.commons.StringHelper;
import com.hk.commons.entity.sys.UserChangeInfo;
import com.hk.dao.base.impl.BaseServiceImpl;
import com.hk.service.sys.IUserChangeInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserChangeImpl extends BaseServiceImpl<UserChangeInfo> implements IUserChangeInfo {

	private Logger logger = LoggerFactory.getLogger(UserChangeImpl.class);

	@Override
	public UserChangeInfo findById(Long id) {
		return this.getById(id);
	}

	@Override
	public UserChangeInfo findByPhone(String name) {
		HqlFilter hqlFilter = new HqlFilter();
		hqlFilter.addEQFilter("name", name );
		return this.getByFilter(hqlFilter);
	}

	public String getNewOrgFullName(UserChangeInfo userChangeInfo){
		String fullName = "";
		if(StringHelper.isNotEmpty(userChangeInfo.getNewChannelName())){
			fullName+= userChangeInfo.getNewChannelName();
		}

		if(StringHelper.isNotEmpty(userChangeInfo.getNewDepName01())){
			fullName+= "-" +  userChangeInfo.getNewDepName01();
		}

		if(StringHelper.isNotEmpty(userChangeInfo.getNewDepName02())){
			fullName+= "-" +  userChangeInfo.getNewDepName02();
		}

		if(StringHelper.isNotEmpty(userChangeInfo.getNewDepName03())){
			fullName+=  "-" + userChangeInfo.getNewDepName03();
		}

		if(StringHelper.isNotEmpty(userChangeInfo.getNewDepName04())){
			fullName+=  "-" + userChangeInfo.getNewDepName04();
		}

		if(StringHelper.isNotEmpty(userChangeInfo.getNewDepName05())){
			fullName+= "-" +  userChangeInfo.getNewDepName05();
		}

		if(StringHelper.isNotEmpty(userChangeInfo.getNewDepName06())){
			fullName+=  "-" + userChangeInfo.getNewDepName06();
		}

		if(StringHelper.isNotEmpty(userChangeInfo.getNewDepName07())){
			fullName+=  "-" + userChangeInfo.getNewDepName07();
		}

		return fullName;
	}



	@Override
	public void add(UserChangeInfo userChgInfo) {
		super.save(userChgInfo);
	}

	@Override
	public UserChangeInfo getUserByRealName(String realName) {
		HqlFilter hqlFilter = new HqlFilter();
		hqlFilter.addEQFilter("realName", realName );
		return this.getByFilter(hqlFilter);
	}

	@Override
	public List<UserChangeInfo> getAll() {
		HqlFilter hqlFilter = new HqlFilter();
		return this.findByFilter(hqlFilter);
	}
}
